package com.hs.shirodemo2.controller;

import com.hs.shirodemo2.constant.CommonConstant;
import com.hs.shirodemo2.entity.SysRole;
import com.hs.shirodemo2.service.SysRoleService;
import com.hs.shirodemo2.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 新增
     */
    @RequiresPermissions("role:add")
    @PostMapping("/add")
    public Result add(@RequestBody SysRole sysRole) {
        System.out.println(sysRole);
        sysRoleService.add(sysRole);
        return Result.success();
    }

    /**
     * 编辑
     */
    @RequiresPermissions("role:edit")
    @PutMapping("/edit")
    public Result edit(@RequestBody SysRole sysRole) {
        sysRoleService.edit(sysRole);
        return Result.success();
    }

    /**
     * 删除
     */
    @RequiresPermissions("role:remove")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id) {
        sysRoleService.remove(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @RequiresPermissions("role:remove")
    @DeleteMapping("/remove")
    public Result removeBatch(Integer[] ids) {
        sysRoleService.removeBatch(ids);
        return Result.success();
    }

    /**
     * 单条查询
     */
    @RequiresPermissions("role:query")
    @GetMapping("/find/{id}")
    public Result findById(@PathVariable Integer id) {
        return Result.success(sysRoleService.findById(id));
    }

    /**
     * 分页查询
     */
    @RequiresPermissions("role:query")
    @PostMapping("/findPage/{pageNum}/{pageSize}")
    public Result findPage(@PathVariable Integer pageNum,
                           @PathVariable Integer pageSize,
                           @RequestBody SysRole sysRole) {
        return Result.success(sysRoleService.findPage(pageNum, pageSize, sysRole));
    }

    /**
     * 查询
     */
    @RequiresPermissions("role:query")
    @GetMapping("/find")
    public Result find(SysRole sysRole) {
        return Result.success(sysRoleService.find(sysRole));
    }
}